import { createApp } from 'vue'
import pinia from '@/stores'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import router from './router'

import { isNull } from './utils'
import formValidate from './utils/formValidate'
import 'virtual:svg-icons-register'
import '@/styles/index.scss'

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue' // global css

const app = createApp(App)

app.use(pinia)
app.use(router)
pinia.init()
app.use(ElementPlus)

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

pinia.dictStore.initDict().then(() => {
  console.log('数据字典加载成功...')
})

// 定义字典全局方法
app.config.globalProperties.dictList = function (code) {
  return pinia.dictStore.dicts[code]
}

// 表单校验
app.config.globalProperties.formValidate = formValidate
// pinia
app.config.globalProperties.$store = pinia
// 判空函数
app.config.globalProperties.isNull = isNull

app.mount('#app')
